package com.itheima.tingchechang;

import java.util.Random;
import java.util.concurrent.Semaphore;

public class Che implements Runnable {
    private Semaphore park;

    public Che(Semaphore park) {
        this.park = park;
    }

    @Override
    public void run() {
        try {
            //进入停车场
            park.acquire();
            System.out.println(Thread.currentThread().getName()+"进场了");
            Random r = new Random();
            int time = r.nextInt(10) + 1;
            Thread.sleep(time*1000);
            System.out.println(Thread.currentThread().getName()+"停了"+time+"秒");
            //停够了开走
            park.release();
        } catch (InterruptedException e) {


        }
    }
}
